﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <title>排产完成率看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 20px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">排产完成率看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排产计划完成时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData()">查询</el-button>
          <template slot="label">
            <el-popover placement="top-start" title="看板过滤规则:" width="400" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>1. 过滤已关闭批次。</p>
              <p>2. 过滤已标记为不加工工序。</p>
              <p>3. 过滤排产工序工艺版本 ≠ 批次当前工艺版本 数据。</p>
            </el-popover>
          </template>
        </el-form-item>
      </el-form>

      <dv-border-box-11 title="排产完成率">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="chart"></div>
      </dv-border-box-11>

      <el-dialog :title="detail.title" :width="'95%'" :top="'10px'" :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40px"></el-table-column>
          <el-table-column label="操作" width="100px;">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-download" size="mini" @click="exportDetail">
                导出
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="主制分厂" prop="factoryname"></el-table-column>
          <el-table-column label="订单号" prop="mfgordername"></el-table-column>
          <el-table-column label="流水卡号" prop="containername"></el-table-column>
          <el-table-column label="工序号" prop="sequence"></el-table-column>
          <el-table-column label="工序名称" prop="workflowstepname"></el-table-column>
          <el-table-column label="计划完成时间" prop="plandate" :formatter="splitDate"></el-table-column>
          <el-table-column label="完成时间" prop="checkdate" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width='100'>
            <template slot-scope="scope" v-if="scope.row.status">
              <el-tag v-if="scope.row.status === '已完工'" type='success'>{{scope.row.status}}</el-tag>
              <el-tag v-if="scope.row.status === '未完工'" type='danger'>{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[12]" :page-size="detail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="detail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getFactoryListByCode } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { selectdate: '', factoryid: '' },
        detail: {
          dialogVisiable: false,
          queryInfo: {
            selectdate: '',
            title: '',
            currentPage: 1,//当前页
            pageSize: 12//每页显示条数
          },
          dataList: [],
          total: 0,
          title: ''
        },
        title: '',
        subtitle: '',
        factoryList: [],
        rules: {
          selectdate: [{ required: true, message: '排产计划完成时间不能为空', trigger: 'change' }]
        },
        chartHeight: 700,
        chartRow: 1,
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询统计数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const dom = document.getElementById("chart");
              echarts.dispose(dom);
              let chart = echarts.init(dom);
              chart.showLoading(this.loadingConfig);
              const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerStepPlanFinishRateDashBoard.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              chart.hideLoading();
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              if (data.length === 0) { return; }

              echarts.dispose(dom);
              chart = echarts.init(dom);

              let arrDate = [], arrFinishRate = [];
              for (const i of data) {
                arrDate.push(i.plandate);
                arrFinishRate.push(i.finishrate);
              }

              if (this.queryInfo.factoryid == '') {
                this.title = '排产完成率（全部）';
              } else {
                this.factoryList.forEach(item => {
                  if (item.factoryid === this.queryInfo.factoryid) {
                    this.title = `排产完成率（${item.factoryname}）`;
                  }
                })
              }

              this.subtitle = `（${this.queryInfo.selectdate[0]} ~ ${this.queryInfo.selectdate[1]}）`;

              let option = barOption();
              option.legend.data = ['完成率'];//设置图例文字
              option.xAxis.data = arrDate;
              option.yAxis[1].show = false;
              option.xAxis.axisLabel.formatter = data => data.split('T')[0].substring(5);
              option.yAxis[0].axisLabel.formatter = data => data + "%";

              option.series[0].name = "完成率";
              option.series[0].data = arrFinishRate;
              option.series[0].type = 'line';
              option.series[0].lineStyle = { width: 4 };
              option.series[0].symbolSize = 10;
              option.series[0].label.color = colorList.green.color;//设置lable颜色
              option.series[0].itemStyle.color = colorList.green.color;//设置柱状图渐变颜色
              option.series[0].label.formatter = '{c}%';

              chart.setOption(option);
              chart.on('click', (params) => {
                if (params.value == 0) { return; }
                let selectdate = `${this.queryInfo.selectdate[0]}~${this.queryInfo.selectdate[1]}`;
                this.detail.queryInfo.currentPage = 1;
                this.detail.title = `${params.name.split('T')[0]} 排产数据`;
                this.detail.dialogVisiable = true;
                this.detail.queryInfo.selectdate = params.name;
                this.detail.queryInfo.title = `${params.name.split('T')[0]} 排产数据`;
                this.getDetail();
              })
            }
          })
        },
        // 查询明细
        async getDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerStepPlanFinishRateDashBoard.ashx?action=getDetail', {
            type: 'getDetail',
            ...this.queryInfo,
            ...this.detail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getDetail();
        },
        // 导出
        exportDetail() {
          const config = {
            url: '../handler/board/ContainerStepPlanFinishRateDashBoard.ashx?action=getExportExcel',
            data: { type: 'getExportExcel', ...this.queryInfo, ...this.detail.queryInfo }
          }
          exportExcelData(config, this);
        }
      },
      async mounted() {
        this.chartHeight = (window.innerHeight - 140 - this.chartRow * 40) / this.chartRow;
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfMonth, endOfMonth];
        this.factoryList = await getFactoryListByCode({ factoryCode: '601|607|609|600|608' });
        this.queryInfo.factoryid = this.factoryList[0].factoryid;
        this.getData();
      }
    })
  </script>
</body>

</html>